#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
using namespace std;

int Mod(int n,int m)
{
	return n%m;
}

int main3980()
{
	int a,b;
	while (cin >> a >> b)
	{
		cout << Mod(a,b) << endl;
	}
	return 0;
}